package com.liyongjian.xhban;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.liyongjian.xhban.dto.AjaxResponse;
import com.liyongjian.xhban.exception.XHBanException;

@Aspect
@Component
public final class XHBanApiMonitor {

    private Logger log = LoggerFactory.getLogger(XHBanApiMonitor.class);

    @Around(value = "execution(* com.liyongjian.xhban.api.*.*(..))")
    public AjaxResponse aroundLoggerMonitor(ProceedingJoinPoint point) throws Throwable {
        AjaxResponse result = new AjaxResponse(false);
        try {
            result = (AjaxResponse) point.proceed();
        } catch (XHBanException e) {
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        } catch (Exception e) {
            result.setCode("9999");
            result.setMsg("系统繁忙");
            log.error("系统异常", e);
        }
        return result;
    }
}
